package nl.sanity.managers
{
	import nl.sanity.ui.BaseComponent;
	import nl.sanity.ui.helpers.UIAlign;
	
	/**
	 * AlignmentManager
	 *
	 * @langversion ActionScript 3
	 *
	 * @author M.P. Bartnig
	 * @since  17/03/2009
	 */
	public class AlignmentManager
	{
		
		// --- PUBLIC FUNCTIONS ----------------------------------------
	
		public static function align( component:BaseComponent ):void
		{
			if ( !component.alignment ) return;
			
			var alignment:UIAlign = component.alignment;
		
			switch ( alignment.orientation )
			{
				case UIAlign.ALIGN_TOP_LEFT:
					component.x = alignment.marginLeft;
					component.y = alignment.marginTop;
					break;
					
				case UIAlign.ALIGN_TOP_MIDDLE:
					component.x = component.parent.width * 0.5 - component.width * 0.5;
					component.y = alignment.marginTop;
					break;
					
				case UIAlign.ALIGN_TOP_RIGHT:
					component.x = component.parent.width - alignment.marginRight;
					component.y = alignment.marginTop;
					break;
				
				case UIAlign.ALIGN_CENTER_LEFT:
					component.x = alignment.marginLeft;
					component.y = component.parent.height * 0.5 - component.height * 0.5;
					break;
					
				case UIAlign.ALIGN_CENTER_MIDDLE:
					component.x = component.parent.width * 0.5 - component.width * 0.5;
					component.y = component.parent.height * 0.5 - component.height * 0.5;
					break;
					
				case UIAlign.ALIGN_CENTER_RIGHT:
					component.x = component.parent.width - alignment.marginRight;
					component.y = component.parent.height * 0.5 - component.height * 0.5;
					break;
					
				case UIAlign.ALIGN_BOTTOM_LEFT:
					component.x = alignment.marginLeft;
					component.y = component.parent.height - alignment.marginBottom - component.height;
					break;
					
				case UIAlign.ALIGN_BOTTOM_MIDDLE:
					component.x = component.parent.width * 0.5 - component.width * 0.5;
					component.y = component.parent.height - alignment.marginBottom - component.height;
					break;
					
				case UIAlign.ALIGN_BOTTOM_RIGHT:
					component.x = component.parent.width - alignment.marginRight;
					component.y = component.parent.height - alignment.marginBottom - component.height;
					break;
			}
		}

	}
}